package com.hxd.otc.module.convenience.presenter;

import android.support.annotation.NonNull;

import com.hxd.otc.base.BaseBean;
import com.hxd.otc.base.BaseRecyclerPresenter;
import com.hxd.otc.module.convenience.adapter.AppStoreAdapter;
import com.hxd.otc.module.convenience.bean.AppStoreBean;
import com.hxd.otc.module.convenience.contract.AppStoreContract;
import com.hxd.otc.module.convenience.model.MarketModel;
import com.hxd.otc.module.my.bean.BaseListBean;
import com.hxd.otc.net.BaseObserver;

/**
 * Created by lzy on 2019/1/3 0003.
 * description ${应用市场Presenter}
 */
public class AppStorePresenter extends BaseRecyclerPresenter<AppStoreContract.IView, AppStoreAdapter, AppStoreBean> implements AppStoreContract.IPresent {

    private final MarketModel mMarketModel;

    public AppStorePresenter(AppStoreContract.IView iView) {
        super(iView);
        mMarketModel = MarketModel.getInstance();
    }

    @Override
    public void loadData(final boolean isRefresh) {
        mMarketModel.getMarketList(mPageIndex, getPageSize(), new BaseObserver<BaseListBean<AppStoreBean>>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull BaseListBean<AppStoreBean> datas) {
                onLoadDataSuccess(isRefresh, datas.getList());
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                mView.showToast(errMessage);
            }
        }, mView.<BaseBean<BaseListBean<AppStoreBean>>>bindAutoDispose());
    }

    @Override
    public void countDownloadNums(String id) {
        mMarketModel.countDownloadNums(id, new BaseObserver<Object>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull Object o) {
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
            }
        }, mView.<BaseBean<Object>>bindAutoDispose());
    }

}
